package logic

import (
	"com-man-sys1/models/mysql"
	"context"
	"errors"

	"com-man-sys1/goodsrpc/goodsrpc"
	"com-man-sys1/goodsrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品列表方法
func (l *GoodsListLogic) GoodsList(in *goodsrpc.GoodsListRequest) (*goodsrpc.GoodsListResponse, error) {
	// todo: add your logic here and delete this line

	var goods []*goodsrpc.GoodsList

	goods, err := mysql.GoodsList(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("列表失败")
	}
	return &goodsrpc.GoodsListResponse{
		List: goods,
	}, nil
}
